package com.zmn.oms.admin.advice;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.Configuration;

/**
 * 类描述:页面访问统计
 *
 * @author liuying
 * @date 2020/12/03 4:27 下午
 */
@Aspect
@Configuration
@Slf4j
public class PageViewAspect {

    // @Reference(version = com.zmn.uuc.common.constant.DubboConsts.INTERFACE_VERSION, check = false)
    // private OpLogModifyRemoteService opLogModifyRemoteService;

    @Pointcut("@annotation(com.zmn.oms.admin.advice.PageView)")
    public void pointCut() {
    }

    @After("pointCut() && @annotation(pageView)")
    public void pointCut(JoinPoint joinPoint, PageView pageView) {
        try {
//            // 获取 orderId
//            int workIdArgsIdx = pageView.workIdArgsIdx() >= joinPoint.getArgs().length ? 0 : pageView.workIdArgsIdx();
//            Object obj = joinPoint.getArgs()[workIdArgsIdx];
//            Long orderId = 0L;
//            if (obj instanceof Long) {
//                orderId = (Long) obj;
//            } else if (obj instanceof OmsBaseOperator) {
//                OmsBaseOperator omsOperator = (OmsBaseOperator) obj;
//                orderId = omsOperator.getOrderId();
//            }
//
//            RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
//            HttpServletRequest request = (HttpServletRequest) requestAttributes.resolveReference(RequestAttributes.REFERENCE_REQUEST);
//            String ip = HttpUtil.getIPAddress(request);
//            String userAgentStr = request.getHeader("User-Agent");
//            UserAgent userAgent = UserAgent.parseUserAgentString(userAgentStr);
//            LoginStaff loginStaff = StaffAdminService.currentStaff();
//
//            OpLogDIO opLogDIO = new OpLogDIO();
//            opLogDIO.setBizId(orderId);
//            opLogDIO.setEntrance(GateTypeConsts.GATE_PLAT_BACKSTAGE);
//            opLogDIO.setIp(ip);
//            opLogDIO.setLogType(LogConsts.LOG_TYPE_LOOK_ORDER_DETAIL);
//            opLogDIO.setIdentityType(PassConsts.PASS_IDENTITY_TYPE_STAFF);
//            opLogDIO.setIdentityObjectId((long) loginStaff.getStaffId());
//            opLogDIO.setCreateTime(DateUtil.getNow());
//            opLogDIO.setDeviceInfo(userAgentStr);
//            if (Objects.nonNull(userAgent)) {
//                opLogDIO.setBrowser(userAgent.getBrowser().getName());
//                opLogDIO.setOs(userAgent.getOperatingSystem().getName());
//            }
//            log.info("opLogDIO={}", opLogDIO);
//            opLogModifyRemoteService.addOpLog(opLogDIO);

        } catch (Exception ex) {
        }
    }

}
